package com.dao;

import com.entity.Book;
import com.entity.Users;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.List;

public class BooksConnection {
    private Connection getConn() throws SQLException {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        return DriverManager.getConnection("jdbc:mysql://localhost:3306/manger","root","");
    }

    public List<Book> selectALl() throws SQLException {
        QueryRunner queryRunner = new QueryRunner();
        String sql = "select * from books";
        List<Users> query  = null;
        return queryRunner.query(getConn(), sql, new BeanListHandler<>(Book.class));
    }
}
